package com.javatest.validate;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @date 2020-11-10 上午9:26
 */
public class ValidatorTest1 {
    public static void main(String[] args) {
        Validator validator = ValidationUtils.obtainValidator();

        Person person = new Person();
        person.setAge(-1);
        Set<ConstraintViolation<Person>> result = validator.validate(person);

        // 输出校验结果
        result.stream().map(v -> v.getPropertyPath() + " "
                + v.getMessage() + ": "
                + v.getInvalidValue())
                .forEach(System.out::println);
    }
}
